﻿using System;
using Fly.Data;
using FlyWebFrame.Model;

namespace FlyWebFrame.Action.admin
{
    public class courses : baseaction
    {
        public dynamic courselist;

        public int lastindex;
        public int nextindex;
        public int preindex;
        public int pageindexview;
        public int countpage;

        public override void Treat()
        {
            contentleft = "/html/admin/courses.htm";
            page_title = "LEAD Consulting - Quản lý khóa học";
            admin_script = "$('#ad_course').addClass('active');";

            int pageindex;
            Int32.TryParse(GetParameter(0), out pageindex);
            pageindexview = pageindex + 1;

            Courses courses = new Courses();
            courselist = courses.Get(pageindex, 10).Data;
            int total = courses.Get().Data.Length;
            countpage = total / 10;
            if (total % 10 != 0)
            {
                countpage = total / 10 + 1;
            }
            for (int i = 0; i < courselist.Length; i++)
            {
                courselist[i].viTitle = courselist[i].title;
            }
           
            // paging
            if (countpage > 1)
            {
                admin_script += "$('#news-paging').removeClass('hidden')";
                if (pageindex >= countpage - 1)
                {
                    nextindex = pageindex;
                }
                else
                {
                    nextindex = pageindex + 1;
                }
                if (pageindex == 0)
                {
                    preindex = 0;
                }
                else
                {
                    preindex = pageindex - 1;
                }
                lastindex = countpage - 1;
            }
        }
    }
}